/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * BookViewPanel.java
 *
 * Created on 1-gen-2014, 17.43.31
 */

package APP3.bookshop.gui;

import APP3.bookshop.main.BookShop;
import APP3.bookshop.person.publisher.Publisher;
import javax.swing.DefaultListModel;

/**
 *
 * @author finalfire
 */
public class PublisherViewPanel extends javax.swing.JPanel {

    
   private BookShop bookshop;


    PublisherViewPanel(BookShop bookshop) {
        
      this.bookshop=bookshop;
       initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel5 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        PubView_PublisherList = new javax.swing.JList();
        PubView_PubNameLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        PubView_PublisherBookList = new javax.swing.JList();
        PubView_PubDeleteButton = new javax.swing.JButton();

        jLabel5.setText("jLabel5");

        jLabel1.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        jLabel1.setText("View publisher");

        jLabel2.setFont(new java.awt.Font("Lucida Grande", 0, 12)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(51, 51, 51));
        jLabel2.setText("Select a publisher to view related information");

        PubView_PublisherList.setModel(bookshop.getPublisherService().populatePublisherList());
        PubView_PublisherList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                PubView_PublisherListMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(PubView_PublisherList);

        PubView_PubNameLabel.setFont(new java.awt.Font("Lucida Grande", 1, 14)); // NOI18N
        PubView_PubNameLabel.setText("PUBLISHER NAME");

        jLabel8.setForeground(new java.awt.Color(51, 51, 51));
        jLabel8.setText("Books published by");

        jScrollPane2.setViewportView(PubView_PublisherBookList);

        PubView_PubDeleteButton.setText("Delete publisher");
        PubView_PubDeleteButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                PubView_PubDeleteButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 15, Short.MAX_VALUE)
                        .add(jLabel2))
                    .add(jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                    .add(PubView_PubNameLabel)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
                    .add(jLabel8)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, PubView_PubDeleteButton))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(PubView_PubNameLabel)
                .add(18, 18, 18)
                .add(jLabel8)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 96, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(PubView_PubDeleteButton)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void PubView_PublisherListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PubView_PublisherListMouseClicked
       Publisher pub = (Publisher) PubView_PublisherList.getSelectedValue();
       PubView_PublisherBookList.setModel(bookshop.getPublisherService().populatePublisherBooksList(pub));
    }//GEN-LAST:event_PubView_PublisherListMouseClicked

    private void PubView_PubDeleteButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PubView_PubDeleteButtonActionPerformed
        Publisher p = (Publisher) PubView_PublisherList.getSelectedValue();
        bookshop.getPublishers().remove(p);
        PubView_PublisherList.setModel(bookshop.getPublisherService().populatePublisherList());
        PubView_PublisherBookList.setModel(new DefaultListModel());
    }//GEN-LAST:event_PubView_PubDeleteButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton PubView_PubDeleteButton;
    private javax.swing.JLabel PubView_PubNameLabel;
    private javax.swing.JList PubView_PublisherBookList;
    private javax.swing.JList PubView_PublisherList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables

}
